
import { sys, native } from 'cc';
import { BCGameLog } from '../../utils/BCGameLog';
import { BCProjectDefines } from '../../utils/BCProjectDefines';
import { BCPlatformInterface } from './BCPlatformInterface';
import { JSB } from 'cc/env';
import { BCNotificationCenter } from '../BCNotificationCenter';

/**
 * Predefined variables
 * Name = IOSMgr
 * DateTime = Tue Jan 04 2022 10:15:54 GMT+0800 (中国标准时间)
 * Author = 风流鼻涕淌
 * FileBasename = IOSMgr.ts
 * FileBasenameNoExtension = IOSMgr
 * URL = db://assets/Main/script/Controller/platform/IOSMgr.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
 *
 */

const callPlatform = (className: string, funcName: string, arg1: string, ...otherArgs: any[]): any => {
	if (JSB) {
		if (sys.os == sys.OS.IOS) {
			BCGameLog.log('[IOSMgr]', className, funcName);
			return native.reflection.callStaticMethod(className, funcName, arg1, ...otherArgs);
		}
	}
	return null;
};

export class BCIOSMgr extends BCPlatformInterface {
	setScreenOrientation(orientation: BCProjectDefines.ScreenOrientation) {
		throw new Error('Method not implemented.');
	}
	getDeviceId(): string {
		throw new Error('Method not implemented.');
	}
	getAppVersion(): string {
		throw new Error('Method not implemented.');
	}
	showToast(toast: string) {
		throw new Error('Method not implemented.');
	}
	copy(text: string) {
		throw new Error('Method not implemented.');
	}
	sendEvent(eventName: string, params?: Map<string, any>) {
		throw new Error('Method not implemented.');
	}
	vibrate(duration: number) {
		throw new Error('Method not implemented.');
	}	
}

class iosBridge {
	private static m_instance: iosBridge = null;

	static get instance() {
		if (!this.m_instance) this.m_instance = new iosBridge();
		return this.m_instance;
	}

	notifyNetworkStatusChange(status: boolean) {
		BCNotificationCenter.instance.emitEvent(BCProjectDefines.NoticeKey.DeviceNetChange, status);
	}
}

window["App2Game"] = iosBridge.instance;
